package com.zrf.gulimall.ware.service.impl;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zrf.gulimall.common.database.utils.PageUtils;
import com.zrf.gulimall.common.database.utils.Query;
import com.zrf.gulimall.ware.dao.PurchaseDetailDao;
import com.zrf.gulimall.ware.entity.PurchaseDetailEntity;
import com.zrf.gulimall.ware.service.PurchaseDetailService;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;


@Service("purchaseDetailService")
public class PurchaseDetailServiceImpl extends ServiceImpl<PurchaseDetailDao, PurchaseDetailEntity> implements PurchaseDetailService {

	@Override
	public PageUtils queryPage(Map<String, Object> params) {
		String key = (String) params.get("key");
		String status = (String) params.get("status");
		String wareId = (String) params.get("wareId");
		IPage<PurchaseDetailEntity> page = this.lambdaQuery()
				.eq(StrUtil.isNotEmpty(status), PurchaseDetailEntity::getStatus, status)
				.eq(StrUtil.isNotEmpty(wareId), PurchaseDetailEntity::getWareId, wareId)
				.and(StrUtil.isNotEmpty(key), wrapper -> wrapper.eq(PurchaseDetailEntity::getPurchaseId, key)
						.or().eq(PurchaseDetailEntity::getSkuId, key))
				.page(new Query<PurchaseDetailEntity>().getPage(params));
		return new PageUtils(page);
	}

	@Override
	public List<PurchaseDetailEntity> queryByPurchaseIds(List<Long> purchaseIds) {
		return this.lambdaQuery()
				.in(CollUtil.isNotEmpty(purchaseIds), PurchaseDetailEntity::getPurchaseId, purchaseIds)
				.list();
	}

}